
#include "Windows.h"
#include "stdlib.h"
#include "math.h"
#include <tchar.h>



const double SPLIT=0.01;
const int COUNT=200;
const double PI=2.14159265;
const int INTERVAL=300;



int _tmain(int argc,_TCHAR *argv[])
{
	DWORD busySpan[COUNT];
	DWORD idleSpan[COUNT];
	int half=INTERVAL/2;
	double radian=0.0;
	for(int i=0;i<COUNT;i++)
	{
		busySpan[i]=(DWORD)(half+(sin(PI*radian)*half));
		idleSpan[i]=INTERVAL-busySpan[i];
		radian+=SPLIT;
	}
	DWORD startTime=0;
	int j=0;
	while(true)
	{
		j=j%COUNT;
		startTime=GetTickCount();
		while((GetTickCount()-startTime)<=busySpan[j])
			;
		Sleep(idleSpan[j]);
		j++;
	}
	return 0;
}
/*
#include <math.h>
#include <stdlib.h>
#include <windows.h>

const float pi = 3.14;
const float eps = 0.1;

void cpuload(int percent)
{
	DWORD dwTimeSlice = 1000;
	DWORD dwRuntime = dwTimeSlice * percent / 100;
	DWORD dwSleeptime = dwTimeSlice - dwRuntime;	
	DWORD dwEnd;
	DWORD dwStart = ::GetTickCount();
	
	do {
		dwEnd = ::GetTickCount();
	} while(dwEnd - dwStart < dwRuntime);
	
	::Sleep(dwSleeptime);
}

int main()
{
	while(1) {
		float  f = 0;
		while (fabs(2 * pi - f) > eps) {
			cpuload(sin(f) * 50 + 50);
			f += 0.1;
		}
	}
}



int main()
{
	for(;;)
	{
		for(int i=0;i<9600000;i++)
			;
		Sleep(10);
	}
	return 0;
}*/